package doublelist;

import java.util.*;

public class ZDemo1 {
    public static void main(String[] args) {
        //当涉及到统计时默认使用 HashMap，如果涉及到排序使用 TreeMap
        String str = "babcabcdabaababcabcdabcde";

        TreeMap<Character,Integer> list = new TreeMap<>();

        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if(list.containsKey(c)){
                list.put(c,list.get(c)+1);
            } else {
                list.put(c,1);
            }
        }
//        Set<Map.Entry<Character,Integer>> array = list.entrySet();
//        StringBuilder s = new StringBuilder();
//        for(Map.Entry<Character,Integer> c:array){
//           s.append(c.getKey()).append("(").append(c.getValue()).append(") ");
//      }
//        array.forEach(entry ->s.append(entry.getKey()).append("(").append(entry.getValue()).append(") "));
//        System.out.println(s);
        StringJoiner s = new StringJoiner("");
        list.forEach((key,value)-> s.add(key+"("+value+") "));
        System.out.println(s);
    }
}
